package com.sdgs.paas.sdk.core.web.client;

import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.Assert;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.RestTemplate;

/**
 * SDK  异步REST请求操作对象
 *
 * @author wjj
 *
 */
public class PaasAsyncRestTemplate extends AsyncRestTemplate {

	
	private String type;
	private RestTemplate syncTemplate;
	
	public PaasAsyncRestTemplate(){
		this(new SimpleAsyncTaskExecutor(),"internal");
	}
	
	
	public PaasAsyncRestTemplate(AsyncListenableTaskExecutor taskExecutor,String type) {
		Assert.notNull(taskExecutor, "AsyncTaskExecutor must not be null");
		SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
		requestFactory.setTaskExecutor(taskExecutor);
		this.setSyncTemplate(new PaasRestTemplate(requestFactory,type));
		setAsyncRequestFactory(requestFactory);
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}


	public RestTemplate getSyncTemplate() {
		return syncTemplate;
	}


	public void setSyncTemplate(RestTemplate syncTemplate) {
		this.syncTemplate = syncTemplate;
	}
	
}